<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>订单支付</title>
    <meta name="keywords" content="支付" />
    <meta name="description" content="支付" />
    <meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width,viewport-fit=cover">
    <link th:href="@{/shoppingApi/css/public.css}" rel="stylesheet">
    <link th:href="@{/shoppingApi/css/weui.min.css}" rel="stylesheet">
    <link th:href="@{/shoppingApi/css/jquery-weui.min.css}" rel="stylesheet">
    <link th:href="@{/shoppingApi/css/accsetting.css}" rel="stylesheet">
    <link th:href="@{/shoppingApi/css/pay.css}" rel="stylesheet">
    <style type="text/css">
        /*.passwordgrid li{*/
            /*border: #323232;*/
        /*}*/
    </style>
</head>
<body>
<div class="main pay">
    <div class="main_con c323232">
        <!--<p class="order_title pl15 pr15 bgfff ft17 c323232 ftc flex flex-ac">-->
        <!--<img class="back" src="./images/back.png">-->
        <!--<span class="it1">在线支付</span>-->
        <!--</p>-->
        <p class="heigth45 pl15 pr15 shop flex bgfff flex-ac">
            <img th:src="@{/shoppingApi/images/carttip.png}">
            <span class="c323232 ml5 it1">
                 <img class="shopimg db" th:src="@{/shoppingApi/images/shopimg.png}">
                <!--<span class="ft14 db shoptitle">新零售微店</span>-->
                <!--<span class="ft7 db shopeng">YUNCHUANGSHEQU</span>-->
            </span>
            <span class="ft15 cf70029 fr">
                <span class="c323232">总需支付</span>
                <span class="ft15"><i>￥</i><i class="real-pay" th:realPay="${orderPay.order.realPay}" th:freight="${orderPay.order.freight}"  th:if="${orderPay!=null}" th:text="${orderPay.order.realPay+orderPay.order.freight}"></i></span>
                <input type="hidden" class="orderNo" name="orderNo" th:if="${orderPay!=null}" th:value="${orderPay.order.orderNo}"/>
                <input type="hidden" class="orderId" name="orderId"  th:if="${orderPay!=null}" th:value="${orderPay.order.orderId}"/>
            </span>
        </p>
        <div class="mt15 pl15 pr15 pt15 card bgfff">
            <ul class="overflow">
                <!--消费积分支付-->
                <li class="flex flex-pj flex-ac mb15 cost-inter ">
                    <div>
                        <p>
                            <span class="ft17 c000" th:if="${orderPay!=null}" th:text="${'使用'+orderPay.WebConfig.finacename4}"></span>
                            <span class="ft10 cf70029">(抵扣)</span>
                        </p>
                        <!--<p th:if="${orderPay.costinter<=0}" class="ft10 c000 mt5"th:text="${'(当前您共有￥'+orderPay.costinter+orderPay.WebConfig.finaceName4+')'}">(当前您共有￥0.00)</p>-->
                        <p class="ft10 c000 mt5" >
                            <span>(当前您共有￥</span><span class="costinter-sum" th:if="${orderPay!=null}" th:text="${#numbers.formatDecimal(orderPay.costinter,1,2)}"></span><span  th:if="${orderPay!=null}" th:text="${orderPay.WebConfig.finacename4}"></span><span>)</span>
                        </p>
                    </div>
                    <div  class="costinter-pay">
                        <!--消费积分为0-->
                        <!--<span class="ft17 cf70029 mr10"  th:if="${orderPay.costinter<=0}"><i>-￥</i><i th:id="${'costinter'+orderPay.order.orderId}"></i>0.00</span>-->
                        <span class="ft17 cf70029 mr10" ><i>-￥</i><i class="costinter-pay-total">0.00</i></span>
                        <!--消费积分大于支付金额-->
                        <!--<span class="ft17 cf70029 mr10"  th:if="${orderPay.costinter-(orderPay.order.realPay+orderPay.order.freight)>=0&&orderPay.costinter>0}"><i>-￥</i><i class="costinter-pay-sum" th:id="${'costinter'+orderPay.order.orderId}" th:text="${#numbers.formatDecimal(orderPay.order.realPay+orderPay.order.freight, 1, 2)}"></i></span>-->
                        <!--消费积分小于支付金额-->
                        <!--<span class="ft17 cf70029 mr10"  th:if="${orderPay.costinter-(orderPay.order.realPay+orderPay.order.freight)<0&&orderPay.costinter>0}"><i>-￥</i><i th:id="${'costinter'+orderPay.order.orderId}" th:text="${#numbers.formatDecimal(orderPay.costinter, 1, 2)}"></i></span>-->
                        <!--消费积分大于支付金额-->
                        <!--<input class="costinter-input" type="checkbox" name="let" th:if="${orderPay.costinter>0}" checked="checked" >-->
                        <input class="costinter-input costinter-box" type="checkbox" name="let" >
                        <!--消费积分小于支付金额-->
                        <!--<input type="checkbox" name="let" th:if="${orderPay.costinter<=0}">-->
                        <!--<input type="checkbox" name="let"th:if="${(orderPay.costinter-orderPay.order.realPay-orderPay.order.freight>0}" checked="checked">-->
                    </div>
                </li>
                <!--积分支付-->
                <li class="flex flex-pj flex-ac mb15  inter-box">
                    <div>
                        <p>
                            <span class="ft17 c000" th:if="${orderPay!=null}" th:text="${'使用'+orderPay.WebConfig.finacename1}"></span><span class="ft10 cf70029">(抵扣)</span>
                        </p>
                        <!--<p th:if="${orderPay.inter<=0}"  class="ft10 c000 mt5">(当前您共有￥0.00)</p>-->
                        <p  class="ft10 c000 mt5" ><!--th:text="${'(当前您共有￥'++orderPay.WebConfig.finacename1+')'}"-->
                            <span>(当前您共有￥</span><span class="inter-sum" th:if="${orderPay!=null}" th:text="${#numbers.formatDecimal(orderPay.inter,1,2)}"></span><span th:if="${orderPay!=null}" th:text="${orderPay.WebConfig.finacename1}"></span><span>)</span>
                        </p>
                    </div>
                    <div class="inter-pay">
                        <!--消费积分与积分之和都为零-->
                        <!--<span th:if="${(orderPay.costinter+orderPay.inter)-(orderPay.order.realPay+orderPay.order.freight)==0}" class="ft17 cf70029 mr10"><i>-￥</i><i th:id="${'inter'+orderPay.order.orderId}">0.00</i></span>-->
                        <span  class="ft17 cf70029 mr10"><i>-￥</i><i class="inter-pay-total">0.00</i></span>
                        <!--两种积分之和大于支付金额-->
                        <!--<span th:if="${(orderPay.costinter+orderPay.inter)-(orderPay.order.realPay+orderPay.order.freight)>=0&&orderPay.costinter-(orderPay.order.realPay+orderPay.order.freight)<0}" class="ft17 cf70029 mr10"><i>-￥</i><i th:id="${'inter'+orderPay.order.orderId}"  th:text="${#numbers.formatDecimal((orderPay.order.realPay+orderPay.order.freight)-(orderPay.costinter), 1, 2)}"></i></span>-->
                        <!--两种积分之和小于支付金额-->
                        <!--<span th:if="${(orderPay.costinter+orderPay.inter)-(orderPay.order.realPay+orderPay.order.freight)<0&&orderPay.costinter<=0}" class="ft17 cf70029 mr10"><i>-￥</i><i th:id="${'inter'+orderPay.order.orderId}"  th:text="${#numbers.formatDecimal(orderPay.inter, 1, 2)}"></i></span>-->
                        <!--两种积分小于支付金额-->
                        <!--<span th:if="${(orderPay.costinter+orderPay.inter)-(orderPay.order.realPay+orderPay.order.freight)<0&&orderPay.costinter>0}" class="ft17 cf70029 mr10"><i>-￥</i><i th:id="${'inter'+orderPay.order.orderId}"  th:text="${#numbers.formatDecimal(orderPay.inter, 1, 2)}"></i></span>-->
                        <!--两种积分大于支付金额-->
                        <!--<span th:if="${orderPay.costinter-(orderPay.order.realPay+orderPay.order.freight)>=0&&orderPay.costinter!=0}" class="ft17 cf70029 mr10"><i>-￥</i><i  class="inter-pay-sum" th:id="${'inter'+orderPay.order.orderId}">0.00</i></span>-->

                        <!--<input class="inter-pay-input" type="checkbox" th:if="${orderPay.costinter-(orderPay.order.realPay+orderPay.order.freight)>0}"  name="let">-->
                        <!--<input type="checkbox" th:if="${orderPay.costinter-(orderPay.order.realPay+orderPay.order.freight)<0&&orderPay.costinter!=0&&orderPay.inter>0}"  name="let"   checked="checked" >-->
                        <!--<input type="checkbox" th:if="${orderPay.costinter==0&&orderPay.inter!=0}"  name="let">-->
                        <!--<input type="checkbox" th:if="${orderPay.costinter<=0&&orderPay.inter<=0}" name="let">-->
                        <input class="inter-pay-input" type="checkbox"  name="let">

                    </div>
                </li>
            </ul>
            <!--<p th:if="${(orderPay.costinter+orderPay.inter)<(orderPay.order.realPay+orderPay.order.freight)}" class="heigth45 ftr ft15 c323232">-->
            <p  class="heigth45 ftr ft15 c323232  web-bank-box  ">
                <span>需网银支付:</span>
                <span class="ft15 cf70029">
                    <i>￥</i><i class="web-bank-pay">0.00</i>
                    <!--<i th:id="${'cash'+orderPay.order.orderId}" th:text="${(orderPay.order.realPay+orderPay.order.freight)-(orderPay.costinter+orderPay.inter)}"></i>-->
                </span>
            </p>

        </div>
        <!--积分不够支付才显示微信支付-->
        <!--<div th:if="${(orderPay.costinter+orderPay.inter)<(orderPay.order.realPay+orderPay.order.freight)}" class="bgfff mt15 way">-->
        <div  class="bgfff mt15 way  weixin-pay" style="display: none;">
            <p class="pl15 pr15 c646464 ft14 paytitle"><span class="ml20">支付方式</span></p>
            <!--微信支付-->
            <div class="flex flex-pj pl15 pr15 flex-ac payway">
                <img th:src="@{/shoppingApi/images/payway1.png}">
                <div class="it1 pr10 flex flex-ac flex-pj">
                    <span class="ft17 c323232 fl">微信支付</span>
                    <span>
                        <input class="fr mt15"  type="radio" id="weixin" name="payway">
                    </span>
                </div>
            </div>
            <!--&lt;!&ndash;积分支付&ndash;&gt;-->
            <!--<div class="flex flex-pj pl15 pr15 flex-ac payway">-->
            <!--<img th:src="@{/shoppingApi/images/my_wallet_integral.png}">-->
            <!--<div class="it1 pr10 flex flex-ac flex-pj">-->
            <!--<span class="ft17 c323232 fl">积分支付</span>-->
            <!--<span>-->
            <!--<input class="fr mt15" checked="checked" type="radio" id="JiFen" name="JiFen">-->
            <!--</span>-->
            <!--</div>-->
            <!--</div>-->
            <!--<div class="flex flex-pj pl15 pr15 flex-ac payway">-->
            <!--<img th:src="@{/shoppingApi/images/payway2.png}">-->
            <!--<div class="it1 pr10 flex flex-ac flex-pj">-->
            <!--<span class="ft17 c323232 fl">支付宝支付</span>-->
            <!--<span>-->
            <!--<input class="fr mt15" type="radio" name="payway">-->
            <!--</span>-->
            <!--</div>-->
            <!--</div>-->
        </div>
        <div class="fixedBox50">
            <div class="fixed-bottom ftc">
                <p  th:if="${orderPay.WebConfig.cashcouponmul!=0}"  class="ft14 cff0000 bgf8d598 heigth30"><i>该订单可返￥</i><i th:text="${#numbers.formatDecimal(orderPay.order.realPay*2, 1, 2)}"></i><i th:if="${orderPay!=null}" th:text="${orderPay.WebConfig.finacename3}"></i></p>
                <!--<p th:cash="${orderPay.order.orderId}" th:no="${orderPay.order.orderNo}" onclick="Pay();" id="pay" class="ft17 cfff bgf70029 heigth50">立即支付</p>-->
                <p  onclick="Pay();" id="pay" th:orderMoney="${orderPay.order.orderMoney}" th:avgCoupon="${orderPay.order.avaCoupon}" th:data="${orderPay.paystate}" th:rank="${orderPay.rank}" class="ft17 cfff bgf70029 heigth50 now-pay">立即支付</p>
                <input type="hidden" th:value="${orderPay.buy}" id="thbuy">
            </div>
        </div>
    </div>
</div>
<div class="vip-tips">恭喜你成为会员！</div>
<!--<a class="back-user-btn" href="/wap/openUserCenter"><span>返回个人中心</span></a>-->
<!--快速导航-->
<div class="mini-mask"></div>
<div class="mini-btn"></div>
<div class="mini-nav">
    <ul>
        <li><a href="/">
            <h5>首页</h5>
        </a></li>
        <li><a href="/wap/selectProductYJAndRjClassfy">
            <h5>分类</h5>
        </a></li>
        <li><a href="javascript:sharebtn()">
            <h5>分享</h5>
        </a></li>
        <li><a href="/wap/openUserCenter">
            <h5>个人中心</h5>
        </a></li>
        <li><a href="javascript:alert('敬请期待...')">
            <h5>店铺</h5>
        </a></li>
        <li><a href="/wap/getCartList">
            <h5>购物车</h5>
        </a></li>
        <li><a href="javascript:alert('敬请期待...')">
            <h5>联系客服</h5>
        </a></li>
    </ul>
</div>
<div id="mini-popup" class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal share-layer">
        <p class="flex mt20 mb20 flex-ac pl15 pr15">
            <span class="ml20 mr20 it1 lineh1"></span>
            <span class="ft14 c323232">分享到</span>
            <span class="ml20 mr20 it1 lineh1"></span>
        </p>
        <ul class="overflow ft14 c323232 ftc">
            <li id="miniShareMessage">
                <img class="wxhaoyou" th:src="@{/shoppingApi/images/share1.png}">
                <p class="mt10 ">微信好友</p>
            </li>
            <li id="miniShareTimeline">
                <img th:src="@{/shoppingApi/images/share2.png}">
                <p class="mt10">朋友圈</p>
            </li>
        </ul>
        <img class="close close-popup" th:src="@{/shoppingApi/images/close3.png}">
    </div>
</div>
<!--/快速导航-->

<div class="weui-mask-custom"></div>
<div id="password" class="weui-dialog-custom">
    <div class="weui-dialog__hd">
        <strong class="weui-dialog__title">支付密码</strong>
    </div>
    <div class="weui-dialog__bd">
        <div class="passwordarea">
            <ul class="passwordgrid">
                <li></li><li></li><li></li><li></li><li></li><li></li>
            </ul>
            <input class="passwordinput" id="passwordinput" autocomplete="new-password" type="password" maxlength="6">
        </div>
    </div>
    <div class="weui-dialog__ft">
        <a href="javascript:;" class="weui-dialog__btn default" style="color: #0f0f0f;font-weight: bold;" id="cancel">取消</a>
        <a href="javascript:;" class="weui-dialog__btn primary" style="color: #f70029;font-weight: bold;" id="confirm">确定</a>
    </div>
</div>

</body>
<script th:src="@{/shoppingApi/js/jquery-3.3.1.min.js}"></script>
<script th:src="@{/shoppingApi/js/jquery-weui.min.js}"></script>
<script th:src="@{/shoppingApi/js/common.js}"></script>
<script type="text/javascript" th:src="@{/shoppingApi/js/plusShare.js}"></script>
<script th:src="@{/shoppingApi/js/mininav.js}"></script>
<script type="application/javascript">
    $(function () {
        loadSumW();
    });

    var payWebCashs=0;
    var orderNo="";
    var avaCoupon=parseFloat($.trim($("#pay").attr('avgCoupon')));
    var orderMoney=parseFloat($.trim($("#pay").attr('orderMoney')));

    //订单号和订单ID
    var orderId=$('.orderId').val();
    //消费积分、积分、网银支付金额
    var payCostinter=$('.costinter-pay-total').html();
    var payInter=$('.inter-pay-total').html();
    var payWebCash=$('.web-bank-pay').html();

    //转换消费积分、积分、网银支付金额类型
    var payCostinters=$.trim(parseFloat(payCostinter));
    var payInters=$.trim(parseFloat(payInter));
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return encodeURIComponent(unescape(r[2]));
        return null;
    }
    $(function () {
        //订单号和订单ID
        orderId=$('.orderId').val();
        //消费积分、积分、网银支付金额
        payCostinter=$('.costinter-pay-total').html();
        payInter=$('.inter-pay-total').html();
        //payWebCash=$('.web-bank-pay').html();
        //转换消费积分、积分、网银支付金额类型
        payCostinters=$.trim(parseFloat(payCostinter));
        payInters=$.trim(parseFloat(payInter));

        var id=$("#pay").attr("cash");
        var no=$.trim(getQueryString("No"));
        orderNo=$.trim($('.orderNo').val());
        payWebCashs=$.trim(parseFloat($('.web-bank-pay').html()));

isChecked();
    });
    // pushHistory();
    window.addEventListener("popstate", function (e) {
        // alert("我监听到了事件啦"); //根据自己的需求实现自己的功能
        $.modal({
            title: "确认放弃付款吗",
            text: "未支付订单将在不久后关闭，请尽快支付哦~",
            buttons: [
                { text: "暂时放弃", onClick: function(){
                        window.location.href='/wap/getOrderList?orderStatus=701';//跳转
                        //console.log(1)
                    } },
                { text: "继续支付", className: "default",onClick: function(){
                        //console.log(2)
                        // Pay();
                    } },
            ]
        });
        // pushHistory(); //注，此处调用，可以用户一直停留着这个页面
    }, false);

    function pushHistory() {
        var state = {
            title: "title",
            url: "#"
        };
        window.history.pushState(state, "title", "#");
    }
    function getOrderState() {
        var url = "/API/Weixin/getOrder?out_trade_no="+orderNo+"&total_fee="+payWebCashs;
        $.ajax({
            url: url,
            // type: "GET",
            async:false,
            success: function(result) {
                if(result){
                    // alert("支付成功!!");
                    window.location="/wap/getOrderDetails?orderNo="+out_trade_no;
                }else{
                    setTimeout('getOrderState()',2000);//轮询执行，2s一次
                }
            }
        });
    }

    var count=0;
    var limit=0;
    function loadSumW() {
        $.ajax({
            url: "/wActivitySum",
            dataType: "json",
            async:false,
            success: function (data) {
                if (data.code == "0") {
                    count=data.count;
                    limit=data.data;
                    // if(count>=2230){
                    //
                    // }
                }

            }
        });
        return count;
    }


    var payFlag=false;
    function Pay() {
        //alert(count+"aa"+limit);
         var buy=parseInt($.trim($("#thbuy").val()));
        //var buy=1;
        if(buy==1){
            //var ss=loadSumW();
            if(count>=limit){
                $.toast("活动结束，敬请期待!",'cancel', function() {});
                return;
            }
        }
        // if(buy==2){
        //     $.toast("当前产品不允许使用消费积分进行支付!",'cancel', function() {});
        //     return;
        // }
        // var idNo = $.trim($('#pay').attr('cash'));//订单orderId
        // var costinter = $.trim($('#costinter' + idNo).html());//消费积分
        // var inter = $.trim($('#inter' + idNo).html());//积分
        // var cash = $.trim($('#cash' + idNo).html());//微信现金支付
        // var outtradeno=$.trim($('#pay').attr('no'));//订单号orderNo

        //获取支付的数据
        if(orderId==""||orderId==null){
            return;
        }
        payWebCash=$('.web-bank-pay').html();
        payWebCashs=$.trim(parseFloat(payWebCash));
         //alert(payCostinters+"--"+payInters+"--"+payWebCash);return;
        // alert(avaCoupon+'--'+orderMoney)

        var buy=parseInt($.trim($("#thbuy").val()));
        //alert(buy);
        if(buy!=1){
            if(parseFloat(avaCoupon)!=parseFloat(orderMoney)) {
                if(payCostinters==0&&payInters==0&&payWebCash==0) {
                    $.toast("金额有误!",'cancel', function() {});
                    return;
                }
            }else {
                if(parseFloat(orderMoney)<3000){
                    $.toast("兑换产品需满3000!",'cancel', function() {});
                    return;
                }
            }
        }

        if(payWebCash==0.00){
            var checked1=$(".costinter-box").is(':checked');
            var checked2=$(".inter-pay-input").is(':checked');
            if(checked1){
                payCostinters=parseFloat($.trim($('.costinter-pay-total').html())).toFixed(2);
            }else {
                payCostinters=0;
            }
            if(checked2){
                payInters=parseFloat($.trim($('.inter-pay-total').html())).toFixed(2);
            }else {
                payInters=0;
            }
            costinterAndInterPay(orderId,payCostinters,payInters,payWebCashs);//积分、消费积分支付
        }else{
            //costinterAndInterPay(orderId,payCostinters,payInters,0);//积分、消费积分支付
            var outtradeno=orderNo;
            if($.trim(outtradeno)!=""){
                weixinPay(outtradeno,payWebCash);//微信支付
            }else {
                $.toast('订单号为空!', 'cancel');
                return;
            }

        }

    }
    //消费积分和积分支付方式
    function costinterAndInterPay(idNo,costinter,inter,cash) {
        // $.confirm("积分支付", '确定支付？', function() {
        //     //点击确认后的回调函数
        //     // 输入密码
        //
        // }, function() {
        //     //点击取消后的回调函数
        //     $.toast('已取消支付', 'cancel')
        //     $('#passwordinput').val('')
        // });
        var state=$.trim(getQueryString("state"));
        if(state=="1"){
            $("#pay").attr("data","true");
        }
        var ishavepay=$.trim($("#pay").attr('data'));
        if(ishavepay!="true"){
            $.alert("订单支付需设置支付密码，请前往设置！", "提示", function() {
                //点击确认后的回调函数
                var redirect = encodeURIComponent('/wap/payOrder?No='+orderNo);
                location.href = '/wap/updatePayPwd?redirect=' + redirect;
            });
        }
        $('#password').addClass('weui-dialog--visible').siblings('.weui-mask-custom').addClass('weui-mask--visible');
        $('#passwordinput').focus();



    }

    // 输入密码后确认
    $(document).on('click', '#confirm', function () {
        var password = $('#passwordinput').val();
        var userNo= $('#transferFrom').val();
        if (!password || password.length < 6) {
            return;
        }
        // var ishavepay=$.trim($("#pay").attr('data'));
        // if(ishavepay!="true"){
        //     $.alert("订单支付需设置支付密码，请前往设置！", "提示", function() {
        //         //点击确认后的回调函数
        //         var redirect = encodeURIComponent('/wap/payOrder?No='+orderNo);
        //         location.href = '/wap/updatePayPwd?redirect=' + redirect;
        //     });
        // }else {
        var checked1=$(".costinter-box").is(':checked');
        var checked2=$(".inter-pay-input").is(':checked');
        if(checked1){
            payCostinters=$.trim($('.costinter-pay-total').html());
        }else {
            payCostinters=0;
        }
        if(checked2){
            payInters=$.trim($('.inter-pay-total').html());
        }else {
            payInters=0;
        }
        //alert(payCostinters+"--"+payInters);return;
            var  checkPas=valPayPwd(password);
            if(checkPas){//密码正确
                $.ajax({
                    url: '/wap/pay',
                    data: {
                        id: orderId,
                        costinter: -payCostinters,
                        inter: -payInters,
                        cash: payWebCashs
                    },
                    dataType: 'json',
                    contentType: 'application/json',
                    async: false,
                    success: function (data) {
                        //alert(JSON.stringify(data));
                        if (data.msgCode == "000000"){//支付成功！
                            $.toast("支付成功!",1000, function() {
                                //更新用户积分和消费积分以及折扣券
                                if($.trim(parseInt($("#pay").attr("rank")))==19){//游客提示
                                    $('.vip-tips').fadeIn();
                                }
                                setTimeout(function() {
                                    window.location="/wap/getOrderDetails?orderNo="+data.data;
                                }, 500);
                            });
                        }else if(data.data == -2){
                            $.toast("数据有误，请返回下单重试!",'cancel', function() {
                                window.location=location;
                            });
                        }else if(data.data==-1) {//支付失败
                            $.toast(data.errorDetail,'cancel', function() {
                                window.location=location;
                            });
                        }
                    }
                });
            }else{
                $.toast("支付密码错误!",'cancel', function() {
                    window.location=location;
                });
            }
        // }
        hidePasswordPop();
    })
    // 输入密码后取消
    $(document).on('click', '#cancel', function () {
        $.toast('您取消了支付', 'cancel')
        hidePasswordPop()
    })
    function hidePasswordPop () {
        $('#password').removeClass('weui-dialog--visible').siblings('.weui-mask-custom').removeClass('weui-mask--visible')
        $('#passwordinput').val('');
    }
    /*确认支付密码*/
    var flag=false;
    function valPayPwd(payPwd) {
        var ss1=false;
        $.ajax({
            async: false,
            type:'post',
            url:'/wap/valPayPwd',
            data:{
                payPwd:payPwd
            },
            success:function (res) {
                ss1= res.flag;
            }
        })
        return ss1;
    }

    /*设置支付密码*/
    function  setPayPwd(userNo) {
        var ss=false;
        $.ajax({
            async: false,
            url:'/wap/selectUserNoByUserNo?userNo='+userNo,
            success:function (res) {
                console.log(res.userNo.payPwd);
                alert(res.userNo.payPwd);
                if(res.userNo.payPwd!=null){
                    ss=true;
                }
            }
        })
        return ss;
    }


    //判断是否是微信浏览器的函数
    function isWeiXin(){
        //window.navigator.userAgent属性包含了浏览器类型、版本、操作系统类型、浏览器引擎类型等信息，这个属性可以用来判断浏览器类型
        var ua = window.navigator.userAgent.toLowerCase();
        //通过正则表达式匹配ua中是否含有MicroMessenger字符串
        if(ua.match(/MicroMessenger/i) == 'micromessenger'){
            return true;
        }else{
            return false;
        }
    }

    /*微信支付*/

    function  weixinPay(outtradeno,cash){
        var checked1=$(".costinter-box").is(':checked');
        var checked2=$(".inter-pay-input").is(':checked');
        if(checked1){
            payCostinters=$.trim($('.costinter-pay-total').html());
        }else {
            payCostinters=0;
        }
        if(checked2){
            payInters=$.trim($('.inter-pay-total').html());
        }else {
            payInters=0;
        }
        if($("#weixin").prop("checked")){ //微信支付
            var urls = "/API/Weixin/upOrder?out_trade_no="+outtradeno+"&inters="+payInters+"&costinters="+payCostinters;
            $.ajax({
                url:urls,
                type: 'post',
                dataType: 'json',
                contentType: 'application/json',
                async: false,
                success: function(data){
                    if(data.msgCode=="1"){
                        var url = "/API/Weixin/downOrder?out_trade_no="+outtradeno+"&cash="+cash;
                        if(isWeiXin()){
                            window.location=url;
                        }else {
                            $.ajax({
                                url:url,
                                type: 'post',
                                dataType: 'json',
                                contentType: 'application/json',
                                async: false,
                                success: function(data){
                                    if(data.msgCode=="2"){
                                        // $.toast("支付成功!",1500, function() {
                                        //
                                        // });
                                        window.location.href=data.detail;
                                    }else if(data.msgCode=="-1"){
                                        $.toast(data.detail, 'cancel');
                                    }else {
                                        $.toast('下单失败!', 'cancel');
                                    }
                                }
                            });
                        }
                    }else {
                        $.toast('下单失败!', 'cancel');
                    }
                }
            });
        }
    }
    /*支付页面*/

    var allPayMoney= parseFloat($.trim($('.real-pay').html()));//商品支付的总金额
    var costinter= parseFloat($.trim($('.costinter-sum').html()));//消费积分
    var inter= parseFloat($.trim($('.inter-sum').html()));//积分
    var web_bank_pay=parseFloat($.trim($(".web-bank-pay").html()));//实际支付
    /*支付的方式*/
    payWayflag=checkPay();

    var payWayflag=false;
    function checkPay() {
        if(costinter>=0&&costinter>=allPayMoney&&inter<allPayMoney) {//消费积分足够支付
             // alert("消费积分足够支付");
                    $('.costinter-pay-total').html(allPayMoney.toFixed(2));
            $('.web-bank-pay').html((0.00).toFixed(2));
            $('.inter-pay-total').html(inter.toFixed(2));
                    $('.costinter-input').prop('checked',true);//只能选择消费积分
            $('.inter-pay-input').prop('checked',false);
            $('.inter-box').css('background','');
                    //$('.weixin-pay').hide();
                    $('.inter-pay-input').prop('disabled',true);
                    $('.inter-pay-input').css('cursor','not-allowed');
                    $('.inter-pay-input').css('before','');
                    //$('.inter-pay-input').css('background','#f0f0f0');
                    $('.cost-inter').css('background','#CCCCCC');
                    payWayflag=true;
        }else if(costinter<allPayMoney&&inter>=allPayMoney){//积分够支付
            // alert("积分够支付");
            if(costinter>0){
                $('.costinter-pay-total').html(costinter.toFixed(2));
                $('.inter-pay-total').html((allPayMoney-costinter).toFixed(2));
                $('.costinter-input').prop('checked',true);
                $('.inter-pay-input').prop('checked',true);
                $('.cost-inter').css('background','#CCCCCC');
                $('.inter-box').css('background','#CCCCCC');
            }else {
                $('.inter-pay-total').html(allPayMoney.toFixed(2));
                $('.inter-pay-input').prop('checked',true);
                $('.inter-box').css('background','#CCCCCC');
            }
            $('.web-bank-pay').html((0.00).toFixed(2));
            //$('.weixin-pay').hide();
            payWayflag=true;
        }else if(costinter<allPayMoney && inter<allPayMoney && (costinter+inter)>=allPayMoney){//两种之和够支付
            // alert("两种之和够支付");
            $('.web-bank-pay').html((0.00).toFixed(2));
                    $('.costinter-pay-total').html(costinter.toFixed(2));
                    $('.inter-pay-total').html((allPayMoney-costinter).toFixed(2));
                    $('.costinter-input').prop('checked',true);
                    $('.inter-pay-input').prop('checked',true);
            $('.cost-inter').css('background','#CCCCCC');
            $('.inter-box').css('background','#CCCCCC');
                    // $('.weixin-pay').hide();
                    payWayflag=true;
        }else if((costinter+inter)<allPayMoney){//和不够支付
            // alert("和不够支付");
                    $('.costinter-pay-total').html(costinter.toFixed(2));
                    $('.inter-pay-total').html(inter.toFixed(2));
                    $('.web-bank-pay').html((allPayMoney-costinter-inter).toFixed(2));
                    $('.costinter-input').prop('checked',true);
                    $('.inter-pay-input').prop('checked',true);
                    $('#weixin').prop('checked',true);
            $('.weixin-pay').show();
            payWayflag=true;
        }else if(inter>=allPayMoney||costinter>=allPayMoney){//任何一种都够支付
            // alert("任何一种都够支付");
            $('.costinter-input').prop('checked',true);
            $('.web-bank-pay').html((0).toFixed(2));
            $('.inter-pay-total').html(allPayMoney.toFixed(2));
            $('.costinter-pay-total').html(allPayMoney.toFixed(2));
            $('.inter-pay-input').prop('checked',false);
            $('.cost-inter').css('background','#CCCCCC');
        }
    }
    function isChecked(){
        $("input:checkbox[name='let']").click(function () {
            var obj=$(this);
            var allPayMoney= parseFloat($.trim($('.real-pay').html()));//商品支付的总金额
            var costinter= parseFloat($.trim($('.costinter-sum').html()));//消费积分
            var inter= parseFloat($.trim($('.inter-sum').html()));//积分
            var dkinter= parseFloat($.trim($('.inter-pay-total').html()));//抵扣积分
            var dkcostinter= parseFloat($.trim($('.costinter-pay-total').html()));//抵扣消费积分
            var checked1=$(".costinter-box").is(':checked');
            var checked2=$(".inter-pay-input").is(':checked');
            if(checked1==true&&checked2==false){
                // alert(1);
                $('.inter-box').removeAttr('style');
                $('#weixin').prop('checked',true);
                $('.web-bank-pay').html((allPayMoney-dkcostinter).toFixed(2));
                payWebCash=(allPayMoney-dkcostinter).toFixed(2);
                if((allPayMoney-dkcostinter)>0){
                    $('.weixin-pay').show();
                    $('.web-bank-box').show();
                }else {
                    $('.weixin-pay').hide();
                    $('.web-bank-box').hide();
                }
            }else if(checked1==false&&checked2==true){
                // alert(2);
                $('.web-bank-pay').html((allPayMoney-dkinter).toFixed(2));
                payWebCash=(allPayMoney-dkinter).toFixed(2);
                $('.inter-box').css('background','#CCCCCC');
                $('.cost-inter').css('background','');
                if((allPayMoney-dkinter)>0){
                    $('.weixin-pay').show();
                    $('.web-bank-box').show();
                }else {
                    $('.weixin-pay').hide();
                    //$('.web-bank-box').hide();
                }
            }else if(checked1==true&&checked2==true){
                checkPay();
            }else if(checked1==false&&checked2==false){
                // alert(4);
                $('.web-bank-pay').html(allPayMoney.toFixed(2));
                payWebCash=allPayMoney;
                if((allPayMoney)>0){
                    $('#weixin').prop('checked',true);
                    $('.cost-inter').css('background','');
                    $('.inter-box').css('background','');
                     $('.inter-pay-input').css('cursor','');
                    $('.inter-pay-input').prop('disabled',false);
                    $('.weixin-pay').show();
                    $('.web-bank-box').show();
                }else {
                    $('.weixin-pay').hide();
                    $('.web-bank-box').hide();
                }
            }
        });
    }
</script>
</html>